package com.toolenaar.socialiceThis;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.facebook.android.FacebookError;
import com.facebook.android.Util;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class InviteFriends extends Activity {

	private ListView _list;
	private Button _button;
	
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
        setContentView(R.layout.invitefriends);
        _list = new ListView(getBaseContext());
        addContentView(_list, new LayoutParams(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT));
        /*if(FriendsTabView.facebook != null)
        {
			JSONObject json;
			try {
				json = Util.parseJson(FriendsTabView.facebook.request("me/friends?access_token="+FriendsTabView._accesCode+"&format=json"));
			
			JSONArray friends = json.getJSONArray("data");
			List<FacebookFriends> _friends = new ArrayList<FacebookFriends>();
			for(int i = 0; i < friends.length(); i++)
			{
				JSONObject friend = Util.parseJson(friends.getString(i));
				String id = friend.getString("id");
				String name = friend.getString("name");
				String image = "http://graph.facebook.com/"+id+"/picture";
				FacebookFriends tempfriend = new FacebookFriends(name, image, id);
				_friends.add(tempfriend);
			}
			_list.setAdapter(new FacebookFriendsAdapter(getBaseContext(), _friends));
			_list.setOnItemClickListener(new OnItemClickListener()
					{
						public void onItemClick(AdapterView<?> adapter, View view, int position, long id) 
						{
							FacebookFriends friend = (FacebookFriends)adapter.getItemAtPosition(position);
							Toast.makeText(getApplicationContext(), friend.getName() + " is gekozen", Toast.LENGTH_SHORT).show();
							//Main.mapTabhost.setCurrentTab(0);
						}
					}
					);
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (FacebookError e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }
        else
        {*/
			String[] temp = new String[]{"facebook == null"};
			_list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, temp));
        //}
		_button = new Button(getBaseContext());
		_button.setText("uitnodigen");
		addContentView(_button, new LayoutParams(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT));
	}
}
